<?php
/**
 * User
 *
 * PHP version 7
 *
 * @category  User
 * @package   App
 * @author    Guojing Liu <liugj@boqii.com>
 * @copyright 2016-2019 guangcheng Co. All Rights Reserved.
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License
 * @version   GIT:<git_id>
 * @link      http://shop.openapi.boqii.com
 */

namespace App;

use Log;
use Cache;
use Illuminate\Auth\Authenticatable;
use Laravel\Lumen\Auth\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;

class User implements AuthenticatableContract, AuthorizableContract
{
	use Authenticatable, Authorizable;

	const TOKEN='comboqiiwwwvetapp';

    /**
    * ValidSign
    *
    * @param mixed $appId
    * @param mixed $nonce
    * @param mixed $timestamp
    * @param mixed $signature
    *
    * @access public
    *
    * @return mixed
    */
    public static function validSign($request)
    {
		log :: info ('sign request params=>'.print_r($request->All(),true));
		log :: info ('sign path params=>'.print_r($request->path(),true));
	
		$arr = $request->All();
		if(empty($arr['Sign']))
			exit(json_encode(array('ResponseStatus'=>500,'ResponseMsg'=>'Sign值不存在','ResponseData'=>'')));
		$sign = $arr['Sign'];
		unset($arr['Sign']);

		ksort($arr);
		$str = '';
		foreach($arr as $val){
			if(is_array($val))
				continue;
			$str.=$val;
		}
		$token = md5($str.self::TOKEN);
#		echo $str,'<br>',$token;
#		exit;
		
		if($token != $sign)
		{
			exit(json_encode(array("ResponseStatus"=>500,"ResponseMsg"=>"加密值不匹配","ResponseData"=>'')));
		}
		return new self();
    }
}
